import request from '@/axios/index'

const baseurl = '/codegen'

export function fetchList(query) {
  for (const key in query) {
    if (query[key] == null || query[key] === '') {
      delete query[key]
    }
  }
  return request({
    url: baseurl + '/show_tables',
    method: 'get',
    params: query,
  })
}

export function generate(data) {
  return request({
    url: baseurl + '/generate',
    method: 'post',
    data,
    responseType: 'blob',
  })
}

export function preview(data) {
  return request({
    url: baseurl + '/preview',
    method: 'post',
    data,
    meta: {
      showLoading: false,
    },
  })
}

export function previewFileName(params) {
  return request({
    url: baseurl + '/preview/fileName',
    method: 'get',
    params,
    meta: {
      showLoading: false,
    },
  })
}

export function previewFilePath(params) {
  return request({
    url: baseurl + '/preview/filePath',
    method: 'get',
    params,
    meta: {
      showLoading: false,
    },
  })
}
